package com.google.coffeeshop.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "invoice_line")
public class InvoiceLineDTO implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@JoinColumn(name = "invoice_id")
	private InvoiceDTO invoice;
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@JoinColumn(name = "order_line_id")
	private OrderLineDTO orderLine;
	
	@Override
	public String toString() {
		String invoiceId = "null";
		if (null != invoice && null != invoice.getId()) {
			invoiceId = invoice.getId().toString();
		}
		return String.format("id=%d, invoiceId=%s", id, invoiceId);
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public InvoiceDTO getInvoice() {
		return invoice;
	}
	public void setInvoice(InvoiceDTO invoice) {
		this.invoice = invoice;
	}
	public OrderLineDTO getOrderLine() {
		return orderLine;
	}
	public void setOrderLine(OrderLineDTO orderLine) {
		this.orderLine = orderLine;
	}
	
}
